$(function(){
	loadTx();
})
//比例
var oldie = /msie\s*(8|7|6)/.test(navigator.userAgent.toLowerCase());

var colorArr = [];
//图形的颜色
colorArr = ["#D15B47","#87CEEB","#87B87F","#d63116","#ff6600","#2ab023","#1e3ae6","#c316a9","#13a9e1"];

function loadTx(){
	var url= "order/showCharts";
	var params = {};
	$.ajax({
		url:url,
		async: false,
		data:params,
		success:function(result){
			if(result.state == 1){
				var list = result.data;
				//计算总和
				var sum = getSum(list);
				//加载div
				getDiv(list,sum);
				//加载图形化
				chartsShow();
				//加载左侧订单类型
				loadLeftType(list,sum);
			}
    	}
	});
}
function getSum(list){
	var sum = 0;
	for(var i=0;i<list.length;i++){
		sum += list[i].count;
	}
	return sum;
}
function getDiv(list,sum){
	var $outDiv = $(".hide_style");
	$outDiv.empty();
	for(var i=0;i<list.length;i++){
		var fz = list[i].count*100;
		var zb = Math.ceil(fz/sum);
		var $innerDiv = '<div class="proportion"> <div class="easy-pie-chart percentage" '+
		'data-percent="'+zb+'" data-color="'+colorArr[i]+'">'+
		'<span class="percent">'+zb+'</span>%</div>'+
		'<span class="name">'+list[i].type+'</span></div>';
		$outDiv.append($innerDiv);
	}
}

function chartsShow(){
	$('.easy-pie-chart.percentage').each(function(){
		$(this).easyPieChart({
			barColor: $(this).data('color'),
			trackColor: '#EEEEEE',
			scaleColor: false,
			lineCap: 'butt',
			lineWidth: 10,
			animate: oldie ? false : 1000,
			size:103
		}).css('color', $(this).data('color'));
	});

	$('[data-rel=tooltip]').tooltip();
	$('[data-rel=popover]').popover({html:true});
}
var color_left = ["pink","grey","red","blue"];
function loadLeftType(list,sum){
	var $ul = $(".b_P_Sort_list");
	var $f_li = $('<li><i class="orange  fa fa-reorder"></i><a href="#">全部订单('+sum+')</a></li>');
	$ul.append($f_li);
	for(var i=0;i<list.length;i++){
		var $li = '<li><i class="fa fa-sticky-note '+color_left[i%4]+' "></i> <a href="#">'+list[i].type+'('+list[i].count+')</a></li>';
		$ul.append($li);
	}
}